@inherits BaseFieldValueComponent<ICollection<Guid>, MultiFileFieldModel>

@namespace FluentCMS.Web.Plugins.Admin.ContentTypeManagement

<FormField Label="@ContentTypeField!.Label" Cols="@Field.FormColWidth" Required="@ContentTypeField!.Required" OnChange="OnFilesChanged">

    <Grid GutterY="GridGutter.Medium">
        <GridItem>
            <Button @onclick="OpenFileSelectorModal">Choose File</Button>            
        </GridItem>

        @if (FieldValue.Value != null)
        {
            <GridItem Small="GridItemColumn.Twelve" GutterY="GridGutter.Small">
                <Stack Items="StackItems.Stretch" Vertical>
                    @foreach (var item in FieldValue.Value)
                    {
                        @if (!string.IsNullOrEmpty(GetFileName(item)))
                        {
                            <Card style="width: 100%;">
                                <CardBody>
                                    <Grid JustifySmall="GridJustify.Between" ItemsSmall="GridItems.Center">
                                        <GridItem>
                                            <Typography>@GetFileName(item)</Typography>
                                        </GridItem>
                                        <GridItem>
                                            <Stack Justify="StackJustify.End">
                                                <Button Size="ButtonSize.Small" Ghost Color="Color.Primary" Href="@GetFileUrl(item)" target="_blank">
                                                    <Icon Name="IconName.Download" />
                                                </Button>
                                                <Button Size="ButtonSize.Small" Ghost Color="Color.Danger" @onclick="() => RemoveValue(item)">
                                                    <Icon Name="IconName.Delete" />
                                                </Button>
                                            </Stack>
                                        </GridItem>
                                    </Grid>
                                </CardBody>
                            </Card>
                        }
                    }
                </Stack>
            </GridItem>
        }
    </Grid>
</FormField>

@if (FileSelectorModalOpen)
{
    <FileSelectorModal FolderId="RootFolder.Id" OnCancel="CloseFileSelectorModal" OnSubmit="OnFileSelectorSubmit"/>
}